<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<style>
    .laytp-container .layui-tree-other .layui-tree-txt {color: #555 !important;}
</style>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">主题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">发件人</label>
                        <div class="layui-input-block">
                            <input type="text" name="uid_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">收件人</label>
                        <div class="layui-input-block">
                            <input type="text" name="recid_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">发件时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="fadt" placeholder="请选择" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="type" name="type" value="1">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md2" id="navselect">
                <div class="navselect_bac">
                    <div class="navselect_div">
                        <div class="navselect_title">邮件</div>
                    </div>
                    <div id="tree_content"></div>
                </div>
            </div>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.id}}')">查看</a>
        {{# if(d.recid<1){ }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_edit('{{d.id}}')">编辑</a>
        {{#} }}
        {{# if(d.reply){ }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_reply('{{d.id}}')">回复</a>
        {{#} }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_delete('{{d.id}}')">删除</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_add('写信')">
            <i class="layui-icon layui-icon-add-1"></i>写信
        </button>
    </div>
</script>

<script>
    var mytable, table, form, treeObj, deptTreeData=[];

    getDeptData();
    function getDeptData(){
        layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
            var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

            facade.ajax({url: ask_email_nav_list}).done(function(res){
                if (res.code === 2000) {
                    deptTreeData = res.data;
                    $("#tree_pand").html('收起');
                    treeObj = tree.render({
                        elem: '#tree_content'
                        ,id: 'tree_content'
                        ,data: deptTreeData
                        ,onlyIconControl: true
                        ,click: function(obj){
                            if(obj.data.id && obj.data.id > 0){
                                $("#type").val(obj.data.id)
                                searchTableFunc(form, table);

                                $('.layui-tree-entry').each(function () {
                                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
                            });
                            $(obj.elem).find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
                            }
                        }
                    });
                    var height = $('.laytp-container').height() - 220 + 'px';
                    $('#tree_content').css('cssText','max-height:'+height);

                    var curType = $("#type").val();
                    $("#tree_content").find('div[data-id="'+curType+'"]').find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
                }
            });
        });
    }

    layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('邮件');
        mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_email_list),where: {type:1}, page: true
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'title',title:'主题',templet: function(d){
                        if($("#type").val() == 1 && d.isread < 1){
                            return '<b>'+d.title+'</b>';
                        }else{
                            return d.title;
                        }
                    }}
                ,{field: 'uid_name', title: '发件人'}
                ,{field: 'faer_name', title: '收件人'}
                ,{field: 'chaoer_name', title: '抄送人'}
                ,{field: 'fadt', title: '发件时间'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, id){
        openPage('show.php?id='+id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_edit(id){
        openPageEdit('edit.php?close=1&id='+id);
    }
    function auth_but_func_reply(id){
        openPageEdit('reply.php?id='+id);
    }
    function auth_but_func_delete(id){
        tit = '是否确认删除？';
        exp = '删除后不可恢复，请谨慎删除';
        layer.confirm("<div class='tit'>"+tit+"</div><div class='exp'>"+exp+"</div>", {
                title:'操作确认',
                icon: 3,
                area:['450px','220px'],
                btn:['确定']
            }, function(conindex){
                facade.ajax({url: ask_email_del, data:{id:id}}).done(function(res){
                    if (res.code === 2000) {
                        facade.success("提交成功!");
                        try {
                            layui.table.reload('datalist');
                            layui.use(['table','form'], function () {
                                var table = layui.table,form = layui.form;
                                searchTableFunc(form, table);
                            })
                            getDeptData();
                        }catch (e) {

                        }
                        layer.close(conindex);
                    }
                });
            }
        )

    }


</script>
</body>
</html>
